home *** CD-ROM | disk | FTP | other *** search
/ Day Cry / Day Cry CD.bin / oh_towns / taropyon / splib / splib.lzh / PRG / ZMODEM / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-07-22  |  13KB  |  654 lines

  1. /*************************************************************************
  2. *    for sz or rz
  3. *************************************************************************/
  4.  
  5. #include    <stdio.h>
  6. #include    <stdlib.h>
  7. #include    <stdarg.h>
  8. #include    <ctype.h>
  9. #include    <string.h>
  10. #include    <time.h>
  11. #include    <setjmp.h>
  12. #ifdef    __HIGHC__
  13. #    include    <msdos.cf>
  14. #    include    <heap.cf>
  15. #endif
  16.  
  17. #include    <sidework.h>
  18. #include    <loader.h>
  19. #include    <egb.h>
  20. #include    <mos.h>
  21. #include    <snd.h>
  22.  
  23. #include    <cnslib.h>
  24. #include    <dialog.h>
  25. #include    <doscons.h>
  26. #include    <dta.h>
  27. #include    <dtaname.h>
  28. #include    <egbmacro.h>
  29. #include    <event.h>
  30. #include    <fslib.h>
  31. #include    <keycode.h>
  32. #include    <kyb.h>
  33. #include    <menu.h>
  34. #include    <moscur.h>
  35. #include    <sbar.h>
  36. #include    <setint.h>
  37. #include    <spicon.h>
  38.  
  39. #include    "usrlib.h"
  40. #include    "rsctrl.h"
  41. #include    "flib.h"
  42. #define    _MSGDAT_DEFINE
  43. #include    "msgdat.h"
  44.  
  45. static    jmp_buf        JmpBuf;
  46.  
  47. static    DLG_T        *Dlg = NULL;
  48. static    CNS_T        *Cns = NULL;
  49. static    EVT_T        *Evt = NULL;
  50. static    SBAR_T        *SbV = NULL;
  51.  
  52. #define                CNS_XS        (80)
  53. #define                CNS_YS        (24)
  54. #define                DLG_XS        (   4 + CNS_XS* 6 + 2+16+4)
  55. #define                DLG_YS        (20+4 + CNS_YS*12 + 4)
  56.  
  57. int        RsPort   = 0;
  58. int        RsBaud   = -1;
  59. int        RsMd     = -1;
  60. int        CtrlX    = FALSE;
  61. int        QuickRet = FALSE;
  62.  
  63. #if    1
  64. static                int        Ch;
  65. static                UINT    Ec;
  66. #define                BREAK_CHECK()    {                        \
  67.     Ch = EVT_getkey( &Ec );                                    \
  68.     if ( Ch == 3 || (Ec&0xFF14) == (KA_C|KA_BIT_CTRL) )        \
  69.         userbreak(1);                                        \
  70. }
  71. #else
  72. #define                BREAK_CHECK()
  73. #endif
  74.  
  75. static CONST char    RECODENAME_MAINARG[] = DTA_RECODENAME_MAINARG;
  76. static CONST char    RECODENAME_DSPCTRL[] = DTA_RECODENAME_DSPCTRL;
  77. DTACTRL_T            *DtaCtrl = NULL;
  78.  
  79. #define    MAIN_EVT_CANCEL    (9999)
  80.  
  81. static    PLT_RGB    PltDat[16] =
  82. {
  83.     /* G R  B                                */
  84.     { 0, 0, 0},    /* C_BALCK                    */
  85.     { 0, 0, 0},    /* C_BLUE or C_THROUGH        */
  86.     { 7, 7, 8},    /* C_RED                    */
  87.     {12,12,13},    /* C_MAGENTA                */
  88.     { 6, 5, 7},    /* C_GREEN                    */
  89.     { 8, 7, 9},    /* C_CYAN                    */
  90.     {10, 9,11},    /* C_YELLOW                    */
  91.     {11,11,12},    /* C_WHITE                    */
  92.  
  93.     { 5, 5, 6},    /* C_HBALCK                    */
  94.     { 0, 0,11},    /* C_HBLUE                    */
  95.     { 0,11, 0},    /* C_HRED                    */
  96.     { 0,11,11},    /* C_HMAGENTA                */
  97.     {11, 0, 0},    /* C_HGEEN                    */
  98.     {11, 0,11},    /* C_HCYAN                    */
  99.     {11,11, 0},    /* C_HYELLOW                */
  100.     {14,14,15}    /* C_HWHITE                    */
  101. };
  102.  
  103. void    userbreak(int level)
  104. {
  105.     extern    void    signal_func(int level);
  106.     signal_func( level );
  107. }
  108.  
  109. static int    ExitLevel = 0;
  110.  
  111. void    userexit(int level)
  112. {
  113.     ExitLevel = level;
  114.     longjmp(JmpBuf, 1);
  115. }
  116.  
  117. void    USR_dspFlush(void)
  118. {
  119.     SbV->top = Cns->dspPos.lnD;
  120.     SbV->dsp = Cns->dspYm;
  121.     SbV->min = 0;
  122.     SbV->max = Cns->linMaxD;
  123.     SBAR_Vredraw(SbV);
  124. }
  125.  
  126. int        USR_putc( int ch )
  127. {
  128.     BREAK_CHECK();
  129.  
  130.     ch &= 0xFF;
  131.     if ( ch == '\n' )
  132.     {
  133.         CNS_puts( Cns,"\r\n");
  134.         USR_dspFlush();
  135.     } else
  136.         CNS_putc( Cns, ch );
  137.     return (ch);
  138. }
  139.  
  140. int        USR_fputc( int ch, FILE *fp )
  141. {
  142.     ch &= 0xFF;
  143.  
  144.     if ( fp )
  145.     {
  146.         if ( fp == stdout || fp == stderr )
  147.             return USR_putc( ch );
  148.         else
  149.             return fputc( ch, fp );
  150.     }
  151. }
  152.  
  153. void    USR_puts( CONST char *s )
  154. {
  155.     BREAK_CHECK();
  156.  
  157.     while ( *s )
  158.     {
  159.         if ( *s == '\n' )
  160.         {
  161.             CNS_puts( Cns, "\r\n" );
  162.         } else
  163.         {
  164.             CNS_putc( Cns, *s );
  165.         }
  166.         ++s;
  167.     }
  168.     USR_dspFlush();
  169. }
  170.  
  171. void    USR_fputs( CONST char *s, FILE *fp )
  172. {
  173.     if ( fp )
  174.     {
  175.         if ( fp == stdout || fp == stderr )
  176.             USR_puts( s );
  177.         else
  178.             fputs( s, fp );
  179.     }
  180. }
  181.  
  182. void    USR_printf( CONST char *form, ... )
  183. {
  184.     va_list        arg;
  185.     char        tmp[BUFSIZ];
  186.  
  187.     va_start( arg, form );
  188.     vsprintf( tmp, form, arg );
  189.     va_end(arg);
  190.  
  191.     USR_puts( tmp );
  192. }
  193.  
  194. void    USR_fprintf( FILE *fp, CONST char *form, ... )
  195. {
  196.     va_list        arg;
  197.     char        tmp[BUFSIZ];
  198.  
  199.     va_start( arg, form );
  200.     vsprintf( tmp, form, arg );
  201.     va_end();
  202.  
  203.     if ( fp )
  204.     {
  205.         if ( fp == stdout || fp == stderr )
  206.             USR_puts( tmp );
  207.         else
  208.             fputs( tmp, fp );
  209.     }
  210. }
  211.  
  212. int        USR_getch(void)
  213. {
  214.     int        ch;
  215.     UINT    ec;
  216.  
  217.     if ( (ch = EVT_getkey( &ec )) == 0xFFFF )
  218.         return (0);
  219.     else
  220.     {
  221.         if ( ch == 3 || (ec&0xFF14) == (KA_C|KA_BIT_CTRL) )
  222.             userbreak(0);
  223.         return (ch & 0xFF);
  224.     }
  225. }
  226.  
  227. static    void    dspFunc( DLG_T *dlg )
  228. {
  229.     int        evtPos = 0;
  230.     int        x1 = dlg->fr.x0;
  231.     int        y1 = dlg->fr.y0;
  232.     int        x2 = x1 + dlg->fr.xs - 1;
  233. //    int        y2 = y1 + dlg->fr.ys - 1;
  234.     int        cx1, cy1, cx2, cy2;
  235.  
  236.     boxfHol( x1+2, y1+2, x2-2, y1+2+18, PSET, C_WHITE, C_HWHITE, C_DARK );
  237.     DSP_str( x1+4, y1+4, C_MBLACK, C_WHITE, 16,
  238.         "%s file(s) with ZMODEM/YMODEM/XMODEM Protocol",
  239. #ifdef    _SZ
  240.         "Send",
  241. #else
  242.         "Receive",
  243. #endif
  244.         MAIN_VER );
  245.  
  246.     /*    [EXIT]â{â^âô    --------------------------------------------*/
  247.     {
  248.         CONST int    x = x2 - 18;
  249.         CONST int    y = y1 + 3;
  250.         EGB_writeMode( EgbPtr, OPAQUE );
  251.         EGB_paintMode( EgbPtr, 0x022);
  252.         EGB_color( EgbPtr, 0, C_DARK );
  253.         EGB_color( EgbPtr, 1, C_WHITE );
  254.         _EGB_PUTBLOCKCOLOR(0, x, y, x+15, y+15, getds(), _icn16x16_closeBtn );
  255.         boxHol( x, y, x+15, y+15, PSET, C_HWHITE, C_DARK );
  256.         _EVT_SETMOS( Evt, evtPos++, MAIN_EVT_CANCEL, MOSEVT_BTN, BTN_LEFT,
  257.             x, y, x+15, y+15, 0, NULL );
  258.    }
  259.  
  260.     /*    â_âCâAâìâOê┌ô«ùp    ----------------------------------------*/
  261.     _EVT_SETMOS( Evt, evtPos++, 0, MOSEVT_NOACT|MOSEVT_QUICK, BTN_LEFT,
  262.         x1+2, y1+2, x2-2, y1+2+18, DLG_defMoveFunc, dlg );
  263.  
  264.     /* âRâôâ\ü[âïù╠êµ    */
  265.     cx1 = x1+4;
  266.     cy1 = y1+24;
  267.     cx2 = x1 + 4 + CNS_XS* 6 - 1;
  268.     cy2 = y1 +24 + CNS_YS*12 - 1;
  269.  
  270.     box( cx1-1, cy1-1, cx2+1, cy2+1, PSET, C_WHITE );
  271.     box( cx1-2, cy1-2, cx2+2, cy2+2, PSET, C_DARK  );
  272.     CNS_changeScnSize( Cns, cx1, cy1, cx2, cy2 );
  273.     CNS_flush( Cns, ERR, ERR);
  274.  
  275.     /* âXâNâìü[âïâoü[    */
  276.     SBAR_Vdsp( SbV, cx2+5, cy1, 16, cy2-cy1+1 );
  277.     USR_dspFlush();
  278. }
  279.  
  280. static int        funcSbarV( int evtNo, SBAR_T *sbV )
  281. {
  282.     CNS_T    *cns = Cns;
  283.  
  284.     if ( cns->linMaxD < cns->dspYm )
  285.     {
  286.         sbV->top = 0;
  287.         return (0);
  288.     } else if ( sbV->top > cns->homeY )
  289.         sbV->top = cns->homeY;
  290.  
  291.     switch( evtNo )
  292.     {
  293.         case    SBEVT_SLIDE:
  294.             MOS_DEC();
  295.             CNS_jump( cns, sbV->top );
  296.             MOS_INC();
  297.             break;
  298.         case    SBEVT_INC:
  299.             if ( sbV->top <= cns->homeY )
  300.             {
  301.                 MOS_DEC();
  302.                 CNS_nextLine( cns, 1 );
  303.                 MOS_INC();
  304.             }
  305.             break;
  306.         case    SBEVT_DEC:
  307.             MOS_DEC();
  308.             CNS_prevLine( cns, 1 );
  309.             MOS_INC();
  310.             break;
  311.     }
  312.     return (0);
  313. }
  314.  
  315.  
  316. static    int        dsp_init(void)
  317. {
  318.     /* âCâxâôâgùp    */
  319.     Evt = EVT_alloc(NULL,8);
  320.     SbV = SBAR_Vopen(Evt, funcSbarV, NULL );
  321.     Cns = CNS_open();
  322.  
  323.     /* â_âCâAâìâOâIü[âvâô    */
  324.     Dlg = DLG_open( DLGPOS_CENTER_OF_SCN, DLGPOS_CENTER_OF_SCN,
  325.         DLG_XS, DLG_YS, C_DLGBASE, dspFunc, NULL );
  326.     if ( Evt == NULL || SbV == NULL || Dlg == NULL || Cns == NULL )
  327.         return (ERR);
  328.     Cns->page = DspCtrl.writePage;
  329.     SbV->attr |= (SBATT_SLIDEQUICK | SBATT_MAXADJUST);
  330.     DLG_dsp(Dlg);
  331.  
  332.     return (NORMAL);
  333. }
  334.  
  335. void    dsp_term(void)
  336. {
  337.     if ( Cns )
  338.     {
  339.         CNS_close( Cns );
  340.         Cns = NULL;
  341.     }
  342.     if ( Dlg )
  343.     {
  344.         DLG_close( Dlg );
  345.         Dlg = NULL;
  346.     }
  347. }
  348.  
  349.  
  350. static    void    hit_any_key(void)
  351. {
  352.     int        ch;
  353.     UINT    ec;
  354.  
  355.     USR_puts("\n**** Hit any key *****\n");
  356.     MOS_curType(MOSCUR_NORMAL);
  357.     MOS_CON();
  358.  
  359.     LOOP
  360.     {
  361.         int        ret;
  362.  
  363.         USR_dspFlush();
  364.  
  365.         if ( (ret = EVT_chk(Evt,EVTIGN_KEY)) >= 0 )
  366.         {
  367.             if ( ret == MAIN_EVT_CANCEL )
  368.                 break;
  369.         } else
  370.         {
  371.             ch = EVT_getkey(&ec);
  372.             if ( ch != 0xFFFF || (ec & 0xFF00) != 0xFF00 )
  373.             {    ec &= 0xFF14;
  374.                 switch( ec )
  375.                 {
  376.                     case    KA_UP:
  377.                     case    KA_W|KA_BIT_CTRL:
  378.                     case    KA_PREV:
  379.                         MOS_DEC();
  380.                         CNS_prevLine( Cns, 1 );
  381.                         MOS_INC();
  382.                         break;
  383.                     case    KA_DOWN:
  384.                     case    KA_Z|KA_BIT_CTRL:
  385.                     case    KA_NEXT:
  386.                         MOS_DEC();
  387.                         CNS_nextLine( Cns, 1 );
  388.                         MOS_INC();
  389.                         break;
  390.                     case    KA_UP|KA_BIT_SHIFT:
  391.                     case    KA_R|KA_BIT_CTRL:
  392.                         MOS_DEC();
  393.                         CNS_prevLine( Cns, Cns->dspYm );
  394.                         MOS_INC();
  395.                         break;
  396.                     case    KA_DOWN|KA_BIT_SHIFT:
  397.                     case    KA_C|KA_BIT_CTRL:
  398.                         MOS_DEC();
  399.                         CNS_nextLine( Cns, Cns->dspYm );
  400.                         MOS_INC();
  401.                         break;
  402.                     default:
  403.                         goto    LOOP_EXIT;
  404.                 }
  405.             } else
  406.                 EVT_idl();
  407.         }
  408.     }
  409. LOOP_EXIT:
  410.     return;
  411. }
  412.  
  413. /*************************************************************************
  414. *    âVâXâeâÇÅëè·ë╗
  415. *************************************************************************/
  416. static    int        init( int *argc, char *